package agency.tango.materialintro.slice;

import agency.tango.materialintroscreen.parallax.ParallaxAbilitySlice;
import agency.tango.materialintro.ResourceTable;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import org.jetbrains.annotations.NotNull;

public class AbilitySliceDemoAbilitySlice extends ParallaxAbilitySlice {
    private float offset = 0.0f;

    @Override
    protected int getLayoutId() {
        return ResourceTable.Layout_ability_slice_demo;
    }

    @Override
    protected void initView() {
        try {
            mRootView = findComponentById(ResourceTable.Id_container);
            Button btAdd = (Button) findComponentById(ResourceTable.Id_bt_plus);
            Button btReduce = (Button) findComponentById(ResourceTable.Id_bt_minus);
            Button btClear = (Button) findComponentById(ResourceTable.Id_bt_clear);
            btAdd.setClickedListener(component -> addOffset());
            btReduce.setClickedListener(component -> reducceOffset());
            btClear.setClickedListener(component -> clearOffset());
        } catch (Exception e) {
        }
    }

    private void clearOffset() {
        offset = 0.0f;
        setOffset(offset);
    }

    private void reducceOffset() {
        if (offset >= 0.1f) {
            offset -= 0.1f;
            setOffset(offset);
        }
    }

    private void addOffset() {
        if (offset <= 0.9f) {
            offset += 0.1f;
            setOffset(offset);
        }
    }

    @Override
    protected @NotNull Component getRootView() {
        return mRootView;
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
